package com.studynotes.dev.tech.common.enums;

import com.studynotes.dev.tech.common.utils.CollectionUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author Liu XiaoJun
 * @description: TODO
 * @date 2025-11-07 16:11:49
 */
@Getter
@AllArgsConstructor
public enum DriverClassNameEnum {

    MYSQL(DBTypeEnum.MYSQL.getCode(),"com.mysql.cj.jdbc.Driver"),
    POSTGRESQL(DBTypeEnum.POSTGRESQL.getCode(),"org.postgresql.Driver"),
    DB2(DBTypeEnum.DB2.getCode(),"com.ibm.db2.jcc.DB2Driver"),
    ORACLE(DBTypeEnum.ORACLE.getCode(),"oracle.jdbc.driver.OracleDriver");

    /**
     * 数据库类型
     */
    private final String code;

    /**
     * 名称
     */
    private final String driverClassName;

    /**
     * 获取枚举
     *
     * @param code 代码项
     * @return 枚举
     */
    public static DriverClassNameEnum of(String code) {
        return CollectionUtil.findFirst(Arrays.asList(values()), item -> item.getCode().equals(code));
    }

}
